package org.example.controller;


import org.example.entity.Post;
import org.example.entity.Response;
import org.example.service.MainService;
import org.example.service.PostService;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/posts")
public class consumerPostController {
    @Autowired
    private MainService postService;

    @PostMapping(value = {"/getAllPosts"})
    public Response getAllPosts(Integer page, String classification, Integer posterId) throws  Exception{
        return this.postService.getAllPosts(page,classification,posterId);
    }


    @PostMapping(value = {"/getPostDetail"})
    public Response getPostDetail(Integer postID) throws  Exception{
        return this.postService.getPostDetail(postID);
    }
    @PostMapping(value = {"/starPost"})
    public Response starPost(Integer postID) throws  Exception{
        return this.postService.starPost(postID);
    }

    @PostMapping(value = {"/updatePost"})
    public Response updatePost(@RequestBody Post post) throws  Exception{
        return this.postService.updatePost(post);
    }

    @PostMapping(value = {"/addPost"})
    public Response addPost(@RequestBody Post post) throws  Exception{
        return this.postService.addPost(post);
    }

//    @PostMapping(value = {"/getAllPosts"})
//    public Response getAllPosts( Integer page, String classification,Integer posterId) throws  Exception{
//        Response response =new Response();
//
//        Page<Post> allPosts = this.postService.getAllPosts(page, classification, posterId);
//
//        response.setHead("OK");
//        response.setCode(1);
//        response.setData(allPosts);
//
//        return response;
//    }
}
